<?php
session_start();
require('mysqli_connect.php');
require('functions.php');
//User Validation...
if(isset($_COOKIE['ID']) && isset($_SESSION['ID']) && isset($_COOKIE['USER'])) { //it's mandatory to have all this variables set to validate, and continue with the page, Login set all this vars
	$user = validation1($_COOKIE['USER'], $_COOKIE['ID'], $_SESSION['ID'], $dbc);
	if(is_array($user)) { //validation done (correct)
		$webpage = '/timetables/files/timetables.php';
		$sections = array();
		$sections[] = 'share';
		$ev = mysqli_real_escape_string($dbc, $_POST['ev']);

		$q = "select * from share where (idevent=".$ev." and iduser=".$user['iduser']." and owner=".$user['iduser'].")";
		$r = @mysqli_query ($dbc, $q);
		$exist = mysqli_fetch_array($r, MYSQLI_ASSOC);
			
			$q = "Delete from share where idevent=".$exist['idevent'];
			$r = @mysqli_query ($dbc, $q);

			$q = "Delete from events where idevent=".$exist['idevent'];
			$r = @mysqli_query ($dbc, $q);

			header('Location: ' .$webpage. '?curr='.$sections[0]);
	}
	else{
		$_SESSION['ID']= 'BANNED';
		header('Location: noob.htm');
	}
}
?>